﻿using CommonTool;
using Motions;
using Station;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tool;
using static GTS.GtsBase;

namespace AutoMachine
{
    public partial class Frm_Air : Form
    {





        #region 窗体实例化
        /// <summary>
        /// 窗体实例化
        /// </summary>
        private static Frm_Air _instance;
        public static Frm_Air Instance
        {
            get
            {
                if (_instance == null || _instance.IsDisposed)
                    _instance = new Frm_Air();
                return _instance;
            }
        }
        #endregion
        public Frm_Air()
        {
            InitializeComponent();
            Resize += new EventHandler(Form1_Resize);
            X = Width;
            Y = Height;
            setTag(this);
            Form1_Resize(new object(), new EventArgs());
        }
        #region 窗体缩放
        private float X;
        private float Y;

        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
                if (con.Controls.Count > 0)
                    setTag(con);
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            foreach (Control con in cons.Controls)
            {

                string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
                float a = Convert.ToSingle(mytag[0]) * newx;
                con.Width = (int)a;
                a = Convert.ToSingle(mytag[1]) * newy;
                con.Height = (int)(a);
                a = Convert.ToSingle(mytag[2]) * newx;
                con.Left = (int)(a);
                a = Convert.ToSingle(mytag[3]) * newy;
                con.Top = (int)(a);
                Single currentSize = Convert.ToSingle(mytag[4]) * Math.Min(newx, newy);
                if (currentSize == 0)
                {
                    currentSize = 1;
                }
                con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                if (con.Controls.Count > 0)
                {
                    setControls(newx, newy, con);
                }
            }

        }

        void Form1_Resize(object sender, EventArgs e)
        {
            float newx = (Width) / X;
            float newy = Height / Y;
            setControls(newx, newy, this);
            //Text = Width.ToString() + " " + Height.ToString();

        }
        #endregion

        private void Frm_Air_Load(object sender, EventArgs e)
        {

            //textBox1.Text = SystemCfg.Param["CmdData10"].Value.ToString();

        }




        private void Button_OKCW1_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("夹爪气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("夹爪气缸1动点电磁阀", true);
        }

        private void Button_OKCCW1_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("夹爪气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("夹爪气缸1原点电磁阀", true);
        }

        private void Button_OKCW2_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("夹爪气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("夹爪气缸2动点电磁阀", true);
        }

        private void Button_OKCCW2_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("夹爪气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("夹爪气缸2原点电磁阀", true);
        }

        private void Button_OKCW3_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("夹爪升降气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("夹爪升降气缸1动点电磁阀", true);
        }

        private void Button_OKCCW3_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("夹爪升降气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("夹爪升降气缸1原点电磁阀", true);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("夹爪升降气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("夹爪升降气缸2动点电磁阀", true);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("夹爪升降气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("夹爪升降气缸2原点电磁阀", true);
        }


        #region 气缸手动动作
        private void button18_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("平台搬运气缸原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("平台搬运气缸动点电磁阀", true);
        }

        private void button17_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("平台搬运气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("平台搬运气缸原点电磁阀", true);
        }

        private void button15_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("出料气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("出料气缸原点电磁阀", true);
        }

        private void button16_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("出料气缸原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("出料气缸动点电磁阀", true);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("取料定位气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("取料定位气缸原点电磁阀", true);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("取料定位气缸原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("取料定位气缸动点电磁阀", true);
        }

        private void button35_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料气缸1原点电磁阀", true);
        }
        private void button36_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料气缸1动点电磁阀", true);
        }

        private void button34_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料气缸2动点电磁阀", true);
        }

        private void button33_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料气缸2原点电磁阀", true);
        }

        private void button32_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("出料气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("出料气缸1动点电磁阀", true);
        }

        private void button31_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("出料气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("出料气缸1原点电磁阀", true);
        }

        private void button30_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("出料气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("出料气缸2动点电磁阀", true);
        }

        private void button29_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("出料气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("出料气缸2原点电磁阀", true);
        }

        private void button106_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸1动点电磁阀", true);
        }

        private void button105_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸1原点电磁阀", true);
        }

        private void button103_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸2原点电磁阀", true);
        }

        private void button104_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸2动点电磁阀", true);
        }

        private void button101_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("入料口平移气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口平移气缸原点电磁阀", true);
        }

        private void button102_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("入料口平移气缸原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口平移气缸动点电磁阀", true);
        }

        private void button99_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("入料口顶升气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口顶升气缸原点电磁阀", true);
        }

        private void button100_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("入料口顶升气缸原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口顶升气缸动点电磁阀", true);
        }

        private void button27_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("接料定位气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1原点电磁阀", true);
        }

        private void button28_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("接料定位气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1动点电磁阀", true);
        }

        private void button25_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("接料定位气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2原点电磁阀", true);
        }

        private void button26_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("接料定位气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2动点电磁阀", true);
        }

        private void button23_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("接料定位气缸3动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3原点电磁阀", true);
        }

        private void button24_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("接料定位气缸3原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3动点电磁阀", true);
        }

        private void button21_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("出料口气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("出料口气缸原点电磁阀", true);
        }

        private void button22_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("出料口气缸原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("出料口气缸动点电磁阀", true);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸1动点电磁阀", true);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸1原点电磁阀", true);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸2原点电磁阀", true);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸3动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸3原点电磁阀", true);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸4动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸4原点电磁阀", true);
        }

        private void button19_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸5动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸5原点电磁阀", true);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸2动点电磁阀", true);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸3原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸3动点电磁阀", true);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸4原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸4动点电磁阀", true);
        }

        private void button20_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸5原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("上料磁吸气缸5动点电磁阀", true);
        }

        private void button43_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸1原点电磁阀", true);
        }

        private void button41_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸2原点电磁阀", true);
        }

        private void button39_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸3动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸3原点电磁阀", true);
        }

        private void button37_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸4动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸4原点电磁阀", true);
        }

        private void button45_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸5动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸5原点电磁阀", true);
        }

        private void button44_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸1动点电磁阀", true);
        }

        private void button42_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸2动点电磁阀", true);
        }

        private void button40_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸3原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸3动点电磁阀", true);
        }

        private void button38_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸4原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸4动点电磁阀", true);
        }

        private void button46_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("磁吸气缸5原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("磁吸气缸5动点电磁阀", true);
        }

        private void button131_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸1原点电磁阀", true);
        }

        private void button129_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸2原点电磁阀", true);
        }

        private void button127_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸3动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸3原点电磁阀", true);
        }

        private void button125_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸4动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸4原点电磁阀", true);
        }

        private void button123_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸5动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸5原点电磁阀", true);
        }

        private void button132_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸1动点电磁阀", true);
        }

        private void button130_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸2动点电磁阀", true);
        }

        private void button128_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸3原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸3动点电磁阀", true);
        }

        private void button126_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸4原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸4动点电磁阀", true);
        }

        private void button124_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("下料上下气缸5原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("下料上下气缸5动点电磁阀", true);
        }
        #endregion

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (MotionMgr.GetInstance().Card.CardIniOK)
            {
                if (MotionMgr.GetInstance().ReadIn("上料气缸1动点"))
                {
                    label_ULoadCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_ULoadCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料气缸1原点"))
                {
                    label_ULoadCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_ULoadCCW1.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("上料气缸2动点"))
                {
                    label_ULoadCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_ULoadCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料气缸2原点"))
                {
                    label_ULoadCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_ULoadCCW2.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("出料气缸1动点"))
                {
                    label_DLoadCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("出料气缸1原点"))
                {
                    label_DLoadCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadCCW1.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("出料气缸2动点"))
                {
                    label_DLoadCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("出料气缸2原点"))
                {
                    label_DLoadCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadCCW2.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("夹爪气缸1动点"))
                {
                    Label_JZCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    Label_JZCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("夹爪气缸1原点"))
                {
                    Label_JZCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    Label_JZCCW1.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("夹爪气缸2动点"))
                {
                    Label_JZCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    Label_JZCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("夹爪气缸2原点"))
                {
                    Label_JZCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    Label_JZCCW2.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("夹爪升降气缸1动点"))
                {
                    Label_JZLiftingCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    Label_JZLiftingCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("夹爪升降气缸1原点"))
                {
                    Label_JZLiftingCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    Label_JZLiftingCCW1.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("夹爪升降气缸2动点"))
                {
                    Label_JZLiftingCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    Label_JZLiftingCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("夹爪升降气缸2原点"))
                {
                    Label_JZLiftingCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    Label_JZLiftingCCW2.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("平台搬运气缸动点"))
                {
                    label_CarryCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CarryCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("平台搬运气缸原点"))
                {
                    label_CarryCCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CarryCCW.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("出料气缸动点"))
                {
                    label_DLoadCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("出料气缸原点"))
                {
                    label_DLoadCCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadCCW.ForeColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("取料定位气缸动点"))
                {
                    label_LocationUpCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_LocationUpCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("取料定位气缸原点"))
                {
                    label_LocationUpCCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_LocationUpCCW.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("入料口夹紧气缸1动点"))
                {
                    label_UloadClampCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UloadClampCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("入料口夹紧气缸1原点"))
                {
                    label_UloadClampCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UloadClampCCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("入料口夹紧气缸2动点"))
                {
                    label_UloadClampCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UloadClampCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("入料口夹紧气缸2原点"))
                {
                    label_UloadClampCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UloadClampCCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("入料口平移气缸动点"))
                {
                    label_ULoadPYCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_ULoadPYCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("入料口平移气缸原点"))
                {
                    label_ULoadPYCCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_ULoadPYCCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("入料口顶升气缸动点"))
                {
                    label_ULoadUPCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_ULoadUPCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("入料口顶升气缸原点"))
                {
                    label_ULoadUPCCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_ULoadUPCCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("接料定位气缸1动点"))
                {
                    label_PickLocationCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_PickLocationCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("接料定位气缸1原点"))
                {
                    label_PickLocationCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_PickLocationCCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("接料定位气缸2动点"))
                {
                    label_PickLocationCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_PickLocationCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("接料定位气缸2原点"))
                {
                    label_PickLocationCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_PickLocationCCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("接料定位气缸3动点"))
                {
                    label_PickLocationCW3.BackColor = Color.LightGreen;
                }
                else
                {
                    label_PickLocationCW3.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("接料定位气缸3原点"))
                {
                    label_PickLocationCCW3.BackColor = Color.LightGreen;
                }
                else
                {
                    label_PickLocationCCW3.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("出料口气缸动点"))
                {
                    label_DLoadKouCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadKouCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("出料口气缸原点"))
                {
                    label_DLoadKouCCW.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadKouCCW.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸1动点"))
                {
                    label_UpCXCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸1原点"))
                {
                    label_UpCXCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸2动点"))
                {
                    label_UpCXCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸2原点"))
                {
                    label_UpCXCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸3动点"))
                {
                    label_UpCXCW3.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCW3.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸3原点"))
                {
                    label_UpCXCCW3.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCCW3.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸4动点"))
                {
                    label_UpCXCW4.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCW4.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸4原点"))
                {
                    label_UpCXCCW4.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCCW4.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸5动点"))
                {
                    label_UpCXCW5.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCW5.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("上料磁吸气缸5原点"))
                {
                    label_UpCXCCW5.BackColor = Color.LightGreen;
                }
                else
                {
                    label_UpCXCCW5.BackColor = Color.DarkGray;
                }

                if (MotionMgr.GetInstance().ReadIn("磁吸气缸1动点"))
                {
                    label_CXCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸1原点"))
                {
                    label_CXCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸2动点"))
                {
                    label_CXCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸2原点"))
                {
                    label_CXCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸3动点"))
                {
                    label_CXCW3.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCW3.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸3原点"))
                {
                    label_CXCCW3.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCCW3.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸4动点"))
                {
                    label_CXCW4.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCW4.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸4原点"))
                {
                    label_CXCCW4.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCCW4.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸5动点"))
                {
                    label_CXCW5.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCW5.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("磁吸气缸5原点"))
                {
                    label_CXCCW5.BackColor = Color.LightGreen;
                }
                else
                {
                    label_CXCCW5.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸1动点"))
                {
                    label_DLoadUDCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸1原点"))
                {
                    label_DLoadUDCCW1.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCCW1.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸2动点"))
                {
                    label_DLoadUDCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸2原点"))
                {
                    label_DLoadUDCCW2.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCCW2.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸3动点"))
                {
                    label_DLoadUDCW3.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCW3.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸3原点"))
                {
                    label_DLoadUDCCW3.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCCW3.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸4动点"))
                {
                    label_DLoadUDCW4.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCW4.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸4原点"))
                {
                    label_DLoadUDCCW4.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCCW4.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸5动点"))
                {
                    label_DLoadUDCW5.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCW5.BackColor = Color.DarkGray;
                }
                if (MotionMgr.GetInstance().ReadIn("下料上下气缸5原点"))
                {
                    label_DLoadUDCCW5.BackColor = Color.LightGreen;
                }
                else
                {
                    label_DLoadUDCCW5.BackColor = Color.DarkGray;
                }
            }
        }

        private void btn_ccd1cmd_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 1; i++)
            {
                MotionMgr.GetInstance().WriteOut("脉冲切换1", false);
                MotionMgr.GetInstance().WriteOut("脉冲切换2", false);
                MotionMgr.GetInstance().WriteOut("脉冲切换3", false);
                MotionMgr.GetInstance().WriteOut("脉冲切换4", false);
                MotionMgr.GetInstance().ResetCmd(3, 10);
                MotionMgr.GetInstance().OpenCmd(3, 10, 0);
                MotionMgr.GetInstance().SetCmdData(3, 10, SystemCfg.Param["CmdData3D2"].Value);

                MotionMgr.GetInstance().ResetCmd(3, 0);
                MotionMgr.GetInstance().OpenCmd(3, 0, 0);
                MotionMgr.GetInstance().SetCmdData(3, 0, SystemCfg.Param["CmdData13_2"].Value);
                MotionMgr.GetInstance().ResetCmd(3, 2);
                MotionMgr.GetInstance().OpenCmd(3, 2, 0);
                MotionMgr.GetInstance().SetCmdData(3, 2, SystemCfg.Param["CmdData13"].Value);

                MotionMgr.GetInstance().ResetCmd(3, 3);
                MotionMgr.GetInstance().OpenCmd(3, 3, 0);
                MotionMgr.GetInstance().SetCmdData(3, 3, SystemCfg.Param["CmdDataJG2"].Value);
                MotionMgr.GetInstance().ResetCmd(3, 5);
                MotionMgr.GetInstance().OpenCmd(3, 5, 0);
                MotionMgr.GetInstance().SetCmdData(3, 5, SystemCfg.Param["CmdDataCT2"].Value);
              
                AbsMove("FlyFilming3", "磁通量检测Z轴检测位");
                AbsMove("FlyFilming3", "双工位飞拍2结束位");
                WaitAbs("FlyFilming3", "磁通量检测Z轴检测位");
                WaitAbs("FlyFilming3", "双工位飞拍2结束位");

                AbsMove("FlyFilming2", "磁通量检测Z轴安全位");
                AbsMove("FlyFilming3", "双工位飞拍2安全位");
                WaitAbs("FlyFilming2", "磁通量检测Z轴安全位");
                WaitAbs("FlyFilming3", "双工位飞拍2安全位");
                Thread.Sleep(1000);
            }
            MessageBox.Show("运行完毕");

        }
        public static decimal GetMin(List<decimal> numbers)
        {
            decimal min = numbers[0];
            for (int i = 0; i < numbers.Count; i++)
            {
                if (min > numbers[i])
                {
                    min = numbers[i];
                }
            }
            return min;
        }
        public static decimal GetMax(List<decimal> numbers)
        {

            decimal max = numbers[0];
            for (int i = 0; i < numbers.Count; i++)
            {
                if (max < numbers[i])
                {
                    max = numbers[i];
                }
            }
            return max;
        }
        private static string DOEDataString(string[] ListData)
        {
            decimal[] dec1 = new decimal[4];
            string s1 = string.Join(",", ListData.ToArray());


            List<decimal> ListDec1 = new List<decimal>();
            for (int i = Convert.ToInt32(ListData.Count() * 0.205); i < Convert.ToInt32(ListData.Count() * 0.41); i++)
            {
                ListDec1.Add(decimal.Parse(ListData[i]));
            }
            if (ListDec1[Convert.ToInt32(ListDec1.Count * 0.5)] < 0)
            {

                dec1[0] = GetMin(ListDec1);
            }
            else
            {
                dec1[0] = GetMax(ListDec1);
            }


            List<decimal> ListDec2 = new List<decimal>();
            for (int i = Convert.ToInt32(ListData.Count() * 0.40); i < Convert.ToInt32(ListData.Count() * 0.555); i++)
            {
                ListDec2.Add(decimal.Parse(ListData[i]));
            }

            if (ListDec2[Convert.ToInt32(ListDec2.Count * 0.5)] < 0)
            {
                dec1[2] = GetMin(ListDec2);
            }
            else
            {
                dec1[2] = GetMax(ListDec2);
            }

            dec1[1] = decimal.Parse(ListData[Convert.ToInt32(ListData.Count() * 0.404)]);

            dec1[3] = decimal.Parse(ListData[Convert.ToInt32(ListData.Count() * 0.56)]);

            //dec1[1] = ListData[Convert.ToInt32(ListData.Count * 0.417)];

            //dec1[3] = ListData[Convert.ToInt32(ListData.Count * 0.726)];



            return DateTime.Now.ToString("HH_mm_ss") + "," + dec1[0] + "," + dec1[1] + "," + dec1[2] + "," + dec1[3] + ", " + s1;
        }


        private void btn_ccd1grab_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            if (btn.Text == "触发拍照")
            {
                btn.Text = "关闭拍照";
                MotionMgr.GetInstance().SetCmdDO(3, 5);
            }
            else
            {
                btn.Text = "触发拍照";
                MotionMgr.GetInstance().CloseCmdDO(3, 5);
            }
        }

        private void btn_Clear1_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().ResetCmd(3, 5);
        }

        private void button35_Click_1(object sender, EventArgs e)
        {
            AbsMove("FlyFilming1", "上料飞拍开始点");
            WaitAbs("FlyFilming1", "上料飞拍开始点");
            QG_定位夹紧();
            Thread.Sleep(500);

            QG_定位张开();
            Thread.Sleep(500);
            for (int i = 0; i < 1; i++)
            {
                AbsMove("FlyFilming1", "上料飞拍开始点");
                WaitAbs("FlyFilming1", "上料飞拍开始点");
                MotionMgr.GetInstance().ResetCmd(1, 2);
                MotionMgr.GetInstance().OpenCmd(1, 2, 1);
                MotionMgr.GetInstance().SetCmdData(1, 2, SystemCfg.Param["CmdData1"].Value);
                MotionMgr.GetInstance().ResetCmd(1, 0);
                MotionMgr.GetInstance().OpenCmd(1, 0, 1);
                MotionMgr.GetInstance().SetCmdData(1, 0, SystemCfg.Param["CmdData2"].Value);
                MotionMgr.GetInstance().ResetCmd(1, 1);
                MotionMgr.GetInstance().OpenCmd(1, 1, 1);
                MotionMgr.GetInstance().SetCmdData(1, 1, SystemCfg.Param["CmdData3"].Value);
                MotionMgr.GetInstance().ResetCmd(1, 5);
                MotionMgr.GetInstance().OpenCmd(1, 5, 1);
                MotionMgr.GetInstance().SetCmdData(1, 5, SystemCfg.Param["CmdData4"].Value);
                MotionMgr.GetInstance().ResetCmd(1, 3);
                MotionMgr.GetInstance().OpenCmd(1, 3, 1);
                MotionMgr.GetInstance().SetCmdData(1, 3, SystemCfg.Param["CmdData5"].Value);
                MotionMgr.GetInstance().ResetCmd(1, 4);
                MotionMgr.GetInstance().OpenCmd(1, 4, 1);
                MotionMgr.GetInstance().SetCmdData(1, 4, SystemCfg.Param["CmdData6"].Value);
                AbsMove("FlyFilming1", "上料飞拍结束点");
                WaitAbs("FlyFilming1", "上料飞拍结束点");




            }
            AbsMove("FlyFilming1", "上料飞拍结束点");
            WaitAbs("FlyFilming1", "上料飞拍结束点");
            MessageBox.Show("运行完毕");

        }
      
        /// <summary>
        /// 获取最小值
        /// </summary>
        /// <param name="numbers"></param>
        /// <returns></returns>
        float GetMin(List<float> numbers, ref int index)
        {
            index = 0;
            float min = numbers[0];
            for (int i = 0; i < numbers.Count; i++)
            {
                if (min > numbers[i])
                {
                    min = numbers[i];
                    index = i + 1;
                }
            }
            return min;
        }
        /// <summary>
        /// 获取最大值
        /// </summary>
        /// <param name="numbers"></param>
        /// <returns></returns>
        float GetMax(List<float> numbers, ref int index)
        {
            index = 0;
            float max = numbers[0];
            for (int i = 0; i < numbers.Count; i++)
            {
                if (max < numbers[i])
                {
                    max = numbers[i];
                    index = i + 1;
                }
            }
            return max;
        }

        /// <summary>
        /// 获取最大值
        /// </summary>
        /// <param name="numbers"></param>
        /// <returns></returns>
        float GetMaxABS(List<float> numbers, ref int index)
        {
            index = 0;
            float max = numbers[0];
            for (int i = 0; i < numbers.Count; i++)
            {
                if (Math.Abs(max) < Math.Abs(numbers[i]))
                {
                    max = numbers[i];
                    index = i + 1;
                }
            }
            return max;
        }
        public string DOEDataString(float[] ListData, int Num,string[] strCJ)
        {
            float[] dec1 = new float[4];
            int A1Index = 0; int A2Index = 0;
            string[] SOrN = new string[6];
            try
            {
                string s1 = string.Join(",", ListData.ToArray());


                List<float> ListDec1 = new List<float>();
                for (int i = Convert.ToInt32(ListData.Count() * 0.205); i < Convert.ToInt32(ListData.Count() * 0.41); i++)
                {
                    ListDec1.Add(ListData[i]);
                }

                dec1[0] = GetMaxABS(ListDec1, ref A1Index);

                A1Index = A1Index + Convert.ToInt32(ListData.Count() * 0.205) - 1;

                List<float> ListDec2 = new List<float>();
                for (int i = Convert.ToInt32(ListData.Count() * 0.40); i < Convert.ToInt32(ListData.Count() * 1); i++)
                {
                    ListDec2.Add(ListData[i]);
                }

                //if (ListDec2[Convert.ToInt32(ListDec2.Count * 0.5)] < 0)
                //{
                //    dec1[2] = GetMin(ListDec2, ref A2Index);
                //}
                //else
                //{
                dec1[1] = GetMaxABS(ListDec2, ref A2Index);
                //}
                A2Index = A2Index + Convert.ToInt32(ListData.Count() * 0.40) - 1;



                //dec1[1] = ListData[Convert.ToInt32(ListData.Count * 0.417)];

                //dec1[3] = ListData[Convert.ToInt32(ListData.Count * 0.726)];
                string[] KOffset1 = SystemCfg.Param["OffsetK1"].Value.Split(',');
                string[] BOffset1 = SystemCfg.Param["OffsetB1"].Value.Split(',');
                string[] KOffset2 = SystemCfg.Param["OffsetK2"].Value.Split(',');
                string[] BOffset2 = SystemCfg.Param["OffsetB2"].Value.Split(',');

                dec1[0] = dec1[0] * float.Parse(KOffset1[Num - 1]) - float.Parse(BOffset1[Num - 1]) + 52;


                dec1[1] = dec1[1] * float.Parse(KOffset2[Num - 1]) - float.Parse(BOffset2[Num - 1]) - 40;




                //if (dec1[0] < 0)
                //{
                //    dec1[0] = (float)(dec1[0] * 1.15 + 37);
                //}
                //else
                //{
                //    dec1[0] = (float)(dec1[0] * 1.111 + 128);
                //}
                //if (dec1[1] < 0)
                //{
                //    dec1[1] = (float)(dec1[1] * 1.15 - 49);
                //}
                //else
                //{
                //    dec1[1] = (float)(dec1[1] * 1.111 - 28);
                //}
                for (int i = 0; i < 6; i++)
                {
                    SOrN[i] = strCJ[i];
                }
                return DateTime.Now.ToString("HH_mm_ss") + "," + dec1[0] + "," + dec1[1] + "," + SOrN[0] + "," + SOrN[1] + "," + SOrN[2] + "," + SOrN[3] + "," + SOrN[4] + "," + SOrN[5] + ", " + s1;
            }
            catch (Exception)
            {
                return DateTime.Now.ToString("HH_mm_ss");
                throw;
            }

        }
        private void button12_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            if (btn.Text == "触发拍照")
            {
                btn.Text = "关闭拍照";
                MotionMgr.GetInstance().SetCmdDO(3, 3);
            }
            else
            {
                btn.Text = "触发拍照";
                MotionMgr.GetInstance().CloseCmdDO(3, 3);
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().ResetCmd(3, 3);
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (MotionMgr.GetInstance().Card.CardIniOK)
            {

            }
        }

        /// <summary>
        /// 等待轴到位
        /// </summary>
        /// <param name="PointName"></param>
        void WaitAbs(string StationName, string PointName, double offset = 0)
        {
            int nAxisNo = SystemCfg.Po(StationName)[PointName].AxisNo;//轴号
            double Speed = SystemCfg.Po(StationName)[PointName].Speed;//速度 
            double Pos = SystemCfg.Po(StationName)[PointName].Point + offset;//目标位置    
            //等待轴到位
            MotionMgr.GetInstance().WaitAbs(nAxisNo, Pos);
            LogView.GetInstance().ShowLog(LogView.LogType.Oper, PointName + "到位,Offset=" + offset.ToString());
        }
        private void AbsMove(string StationName, string PointName, double offset = 0)
        {
            int nAxisNo = SystemCfg.Po(StationName)[PointName].AxisNo;//轴号
            double Speed = SystemCfg.Po(StationName)[PointName].Speed;//速度 
            double Pos = SystemCfg.Po(StationName)[PointName].Point + offset;//目标位置    
            //绝对定位

            MotionMgr.GetInstance().AbsMove(nAxisNo, Pos, Speed);
            Thread.Sleep(10);
        }
        private void button47_Click(object sender, EventArgs e)
        {
            AbsMove("FlyFilming2", "磁通量检测Z轴安全位");

            AbsMove("FlyFilming3", "双工位飞拍2安全位");
            WaitAbs("FlyFilming2", "磁通量检测Z轴安全位");
            WaitAbs("FlyFilming3", "双工位飞拍2安全位");
        }

        private void button48_Click(object sender, EventArgs e)
        {
            AbsMove("FlyFilming3", "磁通量检测Z轴检测位");
            AbsMove("FlyFilming3", "双工位飞拍2结束位");
            WaitAbs("FlyFilming3", "磁通量检测Z轴检测位");
            WaitAbs("FlyFilming3", "双工位飞拍2结束位");
        }

        private void button50_Click(object sender, EventArgs e)
        {
            AbsMove("FlyFilming1", "上料飞拍开始点");
            WaitAbs("FlyFilming1", "上料飞拍开始点");
        }
        private void QG_定位夹紧()
        {

            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸2动点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("入料口夹紧气缸2原点", false);
            MotionMgr.GetInstance().WaitIn("入料口夹紧气缸2动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸1动点电磁阀", true);


            MotionMgr.GetInstance().WaitIn("入料口夹紧气缸1原点", false);
            MotionMgr.GetInstance().WaitIn("入料口夹紧气缸1动点", true);

            Thread.Sleep(500);
            QG_入料口平移气缸动点();
        }
        private void QG_入料口平移气缸原点()
        {
            MotionMgr.GetInstance().WriteOut("入料口平移气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口平移气缸原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("入料口平移气缸动点", false);
            MotionMgr.GetInstance().WaitIn("入料口平移气缸原点", true);
        }
        private void QG_定位张开()
        {
            QG_入料口平移气缸原点();
            Thread.Sleep(1000);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸1原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("入料口夹紧气缸1动点", false);
            MotionMgr.GetInstance().WaitIn("入料口夹紧气缸1原点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口夹紧气缸2原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("入料口夹紧气缸2动点", false);
            MotionMgr.GetInstance().WaitIn("入料口夹紧气缸2原点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("入料口顶升气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口顶升气缸原点电磁阀", true);



            MotionMgr.GetInstance().WaitIn("入料口顶升气缸动点", false);
            MotionMgr.GetInstance().WaitIn("入料口顶升气缸原点", true);
            Thread.Sleep(500);

        }
        private void QG_入料口平移气缸动点()
        {
            MotionMgr.GetInstance().WriteOut("入料口平移气缸原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("入料口平移气缸动点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("入料口平移气缸原点", false);
            MotionMgr.GetInstance().WaitIn("入料口平移气缸动点", true);
        }
        private void button49_Click(object sender, EventArgs e)
        {

            AbsMove("FlyFilming1", "上料飞拍结束点");
            WaitAbs("FlyFilming1", "上料飞拍结束点");
        }

        private void button12_Click_1(object sender, EventArgs e)
        {
            AbsMove("FlyFilming2", "磁通量检测Z轴安全位");

            AbsMove("FlyFilming2", "双工位飞拍1安全位");
            //WaitAbs("FlyFilming2", "磁通量检测Z轴安全位");
            WaitAbs("FlyFilming2", "双工位飞拍1安全位");
        }

        private void button11_Click_1(object sender, EventArgs e)
        {
            AbsMove("FlyFilming2", "磁通量检测Z轴检测位");
            AbsMove("FlyFilming2", "双工位飞拍1结束位");
            //WaitAbs("FlyFilming2", "磁通量检测Z轴检测位");
            WaitAbs("FlyFilming2", "双工位飞拍1结束位");
        }

        private void button53_Click(object sender, EventArgs e)
        {
          
            MessageBox.Show("运行完毕");

        }
       
      

        private void button51_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("进料气缸原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("进料气缸动点电磁阀", true);
        }

        private void button36_Click_2(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("进料气缸动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("进料气缸原点电磁阀", true);
        }



        private void button52_Click_1(object sender, EventArgs e)
        {
            QG_定位夹紧();
            Thread.Sleep(500);

            QG_定位张开();
            Thread.Sleep(500);
        }

        private void button54_Click(object sender, EventArgs e)
        {
            MotionMgr.GetInstance().WriteOut("接料定位气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1动点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2动点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1原点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3动点电磁阀", true);

            MotionMgr.GetInstance().WaitIn("接料定位气缸3原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3原点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2原点", true);
            Thread.Sleep(500);
        }

        private void button55_Click(object sender, EventArgs e)
        {
            AbsMove("FlyFilming2", "双工位飞拍1接料位");
            WaitAbs("FlyFilming2", "双工位飞拍1接料位");
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1动点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2动点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1原点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3动点电磁阀", true);

            MotionMgr.GetInstance().WaitIn("接料定位气缸3原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3原点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2原点", true);
            Thread.Sleep(500);
        }

        private void button56_Click(object sender, EventArgs e)
        {
            AbsMove("FlyFilming3", "双工位飞拍2开始位");
            WaitAbs("FlyFilming3", "双工位飞拍2开始位");
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1动点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2动点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸1原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸1原点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3原点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3动点电磁阀", true);

            MotionMgr.GetInstance().WaitIn("接料定位气缸3原点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3动点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸3原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸3原点", true);
            Thread.Sleep(500);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2动点电磁阀", false);
            MotionMgr.GetInstance().WriteOut("接料定位气缸2原点电磁阀", true);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2动点", false);
            MotionMgr.GetInstance().WaitIn("接料定位气缸2原点", true);
            Thread.Sleep(500);
        }
    }
}
